home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / demo / demosrc / d_mathstat.pro < prev    next >
Text File  |  1997-07-08  |  40KB  |  1,149 lines

  1. ; $Id: d_mathstat.pro,v 1.19 1997/04/24 19:49:34 tremblay Exp $
  2. ;
  3. ;  Copyright (c) 1997, Research Systems, Inc. All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5. ;
  6. ;+
  7. ;  FILE:
  8. ;       d_mathstat.pro
  9. ;
  10. ;  CALLING SEQUENCE: d_mathstat
  11. ;
  12. ;  PURPOSE:
  13. ;       Shows 6 mathematical data analysis routines :
  14. ;       Surface fitting, polynomial fitting, linear regression,
  15. ;       optimization, solving equations, and inegration. 
  16. ;
  17. ;  MAJOR TOPICS: Data analysis and plotting
  18. ;
  19. ;  CATEGORY:
  20. ;       IDL 5.0
  21. ;
  22. ;  INTERNAL FUNCTIONS and PROCEDURES:
  23. ;       pro makeSurfaceFit      - Surface fitting
  24. ;       pro makePolyFit         - Polynomial fitting
  25. ;       pro makeRegression      - Linear regression
  26. ;       pro makeMinimization    - Optimization or minimization
  27. ;       pro makeSolving         - Solving equations
  28. ;       pro GenerateIntegraton  - Integration of functions
  29. ;       pro d_mathstat_event      - Event handler
  30. ;       pro d_mathstatCleanup     - Cleanup
  31. ;       pro d_mathstat            - Main procedure
  32. ;
  33. ;  EXTERNAL FUNCTIONS, PROCEDURES, and FILES:
  34. ;       mathstat.txt
  35. ;
  36. ;  REFERENCE: IDL Reference Guide, IDL User's Guide
  37. ;
  38. ;  NAMED STRUCTURES:
  39. ;       none.
  40. ;
  41. ;  COMMON BLOCS:
  42. ;       none.
  43. ;
  44. ;  MODIFICATION HISTORY:  Written by:  DC, RSI,  1995
  45. ;                         Modified by DAT,RSI,  November 1996
  46. ;                         Combining tour elements 270, 271 and 272
  47. ;-
  48. ;--------------------------------------------------------------------
  49. ;
  50. ;  Purpose:  Compute the function new value for solving equation
  51. ;
  52. function TOUR_230_NEWT, x
  53.     RETURN, [-(x(0)^2 - x(1) - 4.0), x(0)^2 + x(1)^2 - 8.0]
  54. end
  55.  
  56. ;--------------------------------------------------------------------
  57. ;
  58. ;  Purpose:  Compute the function new value  for minimization
  59. ;
  60. function TOUR_231_FUNC, x, All_Elem=all_elem
  61.     IF (KEYWORD_SET(all_elem)) THEN $
  62.         param = x ELSE param = x(0)
  63.     RETURN, SIN(SIN(param^2) - COS(param)) + $
  64.         COS(SIN(param) + SIN(param)^2)
  65. end
  66.  
  67. ;--------------------------------------------------------------------
  68. ;
  69. ;  Purpose:  Create surface fit
  70. ;
  71. pro  MakeSurfaceFit, $
  72.     points, $            ; IN: number of points
  73.     drawXSize, $         ; IN:   x dimension of drawing area
  74.     drawYSize, $         ; IN:   y dimension of drawing area
  75.     drawWindowID         ; IN: window ID
  76.  
  77.     LOADCT, 1 , /SILENT
  78.     TEK_COLOR
  79.     WSET, drawWindowID
  80.  
  81.     x = RANDOMN(s, points)
  82.     y = RANDOMN(s, points)
  83.     z = SIN(x - COS(y)^2) - COS(SIN(x^2) + SIN(y)) + 4.0
  84.  
  85.     zz = MIN_CURVE_SURF(z, x, y, Nx=points, Ny=points)
  86.     min_x = MIN(x, MAX=max_x)
  87.     min_y = MIN(y, MAX=max_y)
  88.     xx = min_x + ((max_x - min_x) * FINDGEN(points) / FLOAT(points-1))
  89.     yy = min_y + ((max_y - min_y) * FINDGEN(points) / FLOAT(points-1))
  90.  
  91.     save_name = !D.Name
  92.     SET_PLOT, 'Z'
  93.     DEVICE, Set_Resolution=[drawXSize, drawYSize]
  94.  
  95.     SHADE_SURF, zz, xx, yy, XSTYLE=1, YSTYLE=1, ZSTYLE=1, $
  96.         TICKLEN=(-0.02), AX=65, AZ=30, BACKGROUND=14, SKIRT=0.0
  97.     img = TVRD(0, 0, drawXSize, drawYSize)
  98.     ERASE
  99.     TV, img
  100.  
  101.     SURFACE, zz, xx, yy, /NODATA, /NOERASE, $
  102.         XSTYLE=1, YSTYLE=1, ZSTYLE=1, $
  103.         TICKLEN=(-0.02), COLOR=3, AX=65, AZ=30, SKIRT=0.0, /SAVE
  104.  
  105.     for i=0, (N_ELEMENTS(x)-1L) do begin
  106.         PLOTS, x(i), y(i), 0.0, PSYM=1, /T3D, /Data, COLOR=3, $
  107.             SYMSIZE=3.0
  108.         PLOTS, [x(i), x(i)], [y(i), y(i)], [0.0, z(i)], $
  109.             /T3D, /DATA, COLOR=2
  110.     endfor
  111.  
  112.     SURFACE, zz, xx, yy, /SAVE, XSTYLE=5, YSTYLE=5, ZSTYLE=5, $
  113.         TICKLEN=(-0.02), /NOERASE, COLOR=15, AX=65, AZ=30, SKIRT=0.0
  114.  
  115.     EMPTY
  116.     img = TVRD(0, 0, drawXSize, drawYSize)
  117.     DEVICE, /CLOSE
  118.     SET_PLOT, save_name
  119.     TV, img
  120.     EMPTY
  121.  
  122.     delt_x = 0.01 / !X.S(1)
  123.     delt_y = 0.01 / !Y.S(1)
  124.     for i=0, (N_ELEMENTS(x)-1L) do begin
  125.        px = [x(i)-delt_x, x(i)+delt_x, x(i)+delt_x, x(i)-delt_x, x(i)-delt_x]
  126.        py = [y(i)-delt_y, y(i)-delt_y, y(i)+delt_y, y(i)+delt_y, y(i)-delt_y]
  127.        ix = FLOAT(points-1) * (px - min_x) / (max_x - min_x)
  128.        iy = FLOAT(points-1) * (py - min_y) / (max_y - min_y)
  129.        pz = INTERPOLATE(zz, ix, iy)
  130.        PLOTS, px, py, pz, /T3D, /DATA, COLOR=0
  131.     endfor
  132.  
  133.     EMPTY
  134.  
  135. end     ;   of MakeSurfaceFit
  136.  
  137. ;--------------------------------------------------------------------
  138. ;
  139. ;  Purpose:  Create polynomial fit
  140. ;
  141. pro  MakePolyFit, $
  142.         points, $      ; IN: number of points
  143.         degree, $      ; IN: polynomial degree
  144.         x, $           ; IN: x array
  145.         y, $           ; IN: y array
  146.         drawWindowID   ; IN: drawing  window ID
  147.  
  148.     LOADCT, 1 , /SILENT
  149.     TEK_COLOR
  150.  
  151.     WSET, drawWindowID
  152.     ERASE
  153.  
  154.     PLOT, x, y, TITLE='Polynomial Fit', $
  155.         /NODATA, COLOR=3, YRANGE=[-2.0, 2.0], $
  156.         POSITION=[0.15, 0.25, 0.9, 0.75], $
  157.         TICKLEN=(-0.02), XSTYLE=1, YSTYLE=1
  158.     EMPTY
  159.     OPLOT, x, y, PSYM=4, COLOR=5
  160.     EMPTY
  161.  
  162.     yy = POLY_FIT(x, y, degree)
  163.     xx = 2.0 * !PI * FINDGEN(256) / 255.0
  164.     yy = POLY(xx, yy)
  165.     OPLOT, xx, yy, COLOR=1, THICK=2
  166.     EMPTY
  167.  
  168. end     ;   of  Make PolyFit
  169.  
  170. ;--------------------------------------------------------------------
  171. ;
  172. ;  Purpose:  Create regression items
  173. ;
  174. pro  MakeRegression, $
  175.         above, $       ; IN: number of outliers above
  176.         below, $       ; IN: number of outliers below
  177.         drawWindowID   ; IN: drawing  window ID
  178.  
  179.     !P.MULTI = [0, 2, 1]
  180.     previousFont = !P.FONT
  181.     !P.FONT = 0
  182.  
  183.     LOADCT, 0 , /SILENT
  184.     TEK_COLOR
  185.  
  186.     points = 51
  187.     x = FINDGEN(points)
  188.  
  189.     ;  Generate the discrete data.
  190.     ;
  191.     y = 0.3 * x - 3.0 + randomn(seed, points)
  192.  
  193.     ;  Generate the outlying data above.
  194.     ;
  195.     ix = ROUND(RANDOMU(seed, above) * FLOAT(points-1))
  196.     y(ix) = y(ix) + RANDOMU(s, above) * 10.0
  197.  
  198.     ;  Generate the discrete data.
  199.     ;
  200.     y = 0.3 * x - 3.0 + randomn(seed, points)
  201.  
  202.     ;  Generate the outlying data above.
  203.     ;
  204.     ix = ROUND(RANDOMU(s, above) * FLOAT(points-1))
  205.     y(ix) = y(ix) + RANDOMU(s, above) * 10.0
  206.  
  207.     ;  Generate the outlying data below.
  208.     ;
  209.     ix = ROUND(RANDOMU(s, below) * FLOAT(points-1))
  210.     y(ix) = y(ix) - RANDOMU(s, below) * 15.0
  211.  
  212.     y = (y > (-20.0)) < 20.0
  213.  
  214.     ;  Compute the fit.
  215.     ;
  216.     result1 = LINFIT(x, y)
  217.     result2 = LADFIT(x, y)
  218.  
  219.     ;  Plot the regression results.
  220.     ;
  221.     WSET, drawWindowID
  222.     ERASE
  223.     xt1 = STRING(result1(1), FORMAT='(F7.5)') + 'x' + $
  224.         STRING(result1(0), FORMAT='(F9.5)')
  225.     PLOT, x, y, /NODATA, YRANGE=[-20, 20], $
  226.         TITLE='Regression Fit', $
  227.         XTITLE=('y = ' + xt1), COLOR=1, XMARGIN=[5,2], YMARGIN=[5,5]
  228.     PLOTS, x, y, PSYM=4, COLOR=2
  229.     y1 = result1(0) + result1(1) * x
  230.     OPLOT, x, y1, THICK=2, COLOR=5
  231.  
  232.     ;  PLOT the least-absolute-deviation results.
  233.     ;
  234.     xt2 = STRING(result2(1), FORMAT='(F7.5)') + 'x' + $
  235.         STRING(result2(0), FORMAT='(F9.5)')
  236.     PLOT, x, y, /NODATA, YRANGE=[-20, 20], TITLE= $
  237.         'Least Absolute Deviation', XTITLE=('y = ' + xt2), $
  238.         COLOR=1, XMARGIN=[5,2], YMARGIN=[5,5]
  239.     PLOTS, x, y, PSYM=4, COLOR=2
  240.     y2 = result2(0) + result2(1) * x
  241.     OPLOT, x, y2, THICK=2, COLOR=5
  242.  
  243.     !P.MULTI = 0
  244.     !P.FONT = previousFont
  245.  
  246. end   ;  of MakeRegression
  247.  
  248. ;--------------------------------------------------------------------
  249. ;
  250. ;  Purpose:  Create minimization item
  251. ;
  252. pro MakeMinimization, $
  253.     drawXSize, $         ; IN:   x dimension of drawing area
  254.     drawYSize, $         ; IN:   y dimension of drawing area
  255.     drawWindowID, $      ; IN:   window ID of drawing area
  256.     pixmapID, $          ; IN:   pixmapID
  257.     sText, $             ; IN: tip text structure
  258.     wText                ; IN: widget text ID
  259.   
  260.  
  261.     LOADCT, 0 , /SILENT
  262.     TEK_COLOR
  263.     sz = 256
  264.     f_sz_m1 = FLOAT(sz - 1)
  265.  
  266.     x = !PI * 3.5 * ((FINDGEN(sz) / f_sz_m1) - 0.5)
  267.     y = TOUR_231_FUNC(x, /All_Elem)
  268.  
  269.     WSET, pixmapID
  270.     PLOT, x, y, YRANGE=[-1.5, 2.5], XSTYLE=1, YSTYLE=1, COLOR=4, $
  271.         /NODATA, TICKLEN=(1.0), XTITLE='X', YTITLE='Y'
  272.     PLOT, x, y, YRANGE=[-1.5, 2.5], XSTYLE=1, YSTYLE=1, COLOR=5, $
  273.         /NODATA, /NOERASE, TICKLEN=(0.0), XTITLE='X', YTITLE='Y'
  274.     PLOT, x, y, YRANGE=[-1.5, 2.5], XSTYLE=5, YSTYLE=5, COLOR=1, $
  275.         /NOERASE, THICK=2, XTITLE='X', YTITLE='Y'
  276.  
  277.     Wset, drawWindowID
  278.     DEVICE, COPY=[0, 0, drawXSize, drawYSize, 0, 0, pixmapID]
  279.  
  280.     p = [0.0, 0.0]
  281.     xi = REPLICATE(0.01, 2, 2)
  282.     ftol = 1.0e-5
  283.  
  284.     NR_Powell, p, xi, ftol, func_min, 'TOUR_231_FUNC'
  285.  
  286.     OPLOT, [0.0], [0.0], PSYM=2, COLOR=7, SYMSIZE=0.5
  287.     OPLOT, [p(0)], [func_min], PSYM=2, COLOR=2, SYMSIZE=0.5
  288.     OPLOT, [p(0)], [func_min], PSYM=4, THICK=2, COLOR=2, SYMSIZE=2.0
  289.  
  290.      minString = $
  291.         'Minimum : ' + $
  292.         (STRING(p(0), FORMAT='(F7.4)') + ', ' + $
  293.         STRING(func_min, FORMAT='(F7.4)'))
  294.     sText.text[5] = minString
  295.     textChange = ['optim1','optim2', 'varia']
  296.     putTips, sText, wText[1], $
  297.         textChange, [0,1,2]
  298.  
  299. end      ;   of makeMinimum
  300.  
  301. ;--------------------------------------------------------------------
  302. ;
  303. ;  Purpose:  Generate the plots for the solving equations demo
  304. ;            The drawing area must be selected apriori
  305. ;
  306. pro MakeSolving, $
  307.     drawXSize, $    ; IN: x dimension of the drawing area
  308.     drawYSize, $    ; IN: y dimension of the drawing area
  309.     sText, $        ; IN: tip text structure
  310.     wText, $        ; IN: widget text ID
  311.     windowID        ; IN: window identifier
  312.  
  313.     WSET, windowID
  314.     LOADCT, 0, /SILENT
  315.     TEK_COLOR
  316.  
  317.     ;  Graph the surfaces.
  318.     ;
  319.     x = (FINDGEN(51) / 5.0) - 5.0
  320.     y = x
  321.  
  322.     xx = x # REPLICATE(1.0, 51)
  323.     yy = TRANSPOSE(xx)
  324.  
  325.     z1 = -(xx^2 - yy - 4.0)
  326.     z2 = xx^2 + yy^2 - 8.0
  327.  
  328.     p = FLTARR(51, 51)
  329.  
  330.     zrange = [-45.0, 45.0]
  331.     save_name = !D.Name
  332.     SET_PLOT, 'Z'
  333.     DEVICE, Set_Resolution=[drawXSize, drawYSize]
  334.     ERASE, 0
  335.     SURFACE, p, x, y, ZRANGE=zrange, $
  336.         COLOR=1, AX=70, AZ=30, TICKLEN=(-0.01), $
  337.         /NODATA, /SAVE, XSTYLE=3, YSTYLE=3, ZSTYLE=3, BACKGROUND=14
  338.  
  339.     SURFACE, p, x, y, ZRANGE=zrange, COLOR=3, /T3D, /NOERASE, $
  340.         XSTYLE=7, YSTYLE=7, ZSTYLE=7
  341.  
  342.     SHADE_SURF, p, x, y, ZRANGE=zrange, COLOR=3, /T3D, /NOERASE, $
  343.         XSTYLE=7, YSTYLE=7, ZSTYLE=7
  344.     img = TVRD(0, 0, drawXSize, drawYSize)
  345.     SET_PLOT, save_name
  346.     TV, img
  347.     EMPTY
  348.  
  349.     SET_PLOT, 'Z'
  350.     SURFACE, z1, x, y, ZRANGE=zrange, COLOR=4, /T3D, /NOERASE, $
  351.         XSTYLE=7, YSTYLE=7, ZSTYLE=7
  352.     SHADE_SURF, z1, x, y, ZRANGE=zrange, COLOR=4, /T3D, /NOERASE, $
  353.         XSTYLE=7, YSTYLE=7, ZSTYLE=7
  354.     img = TVRD(0, 0, drawXSize, drawYSize)
  355.     SET_PLOT, save_name
  356.     TV, img
  357.     EMPTY
  358.  
  359.     SET_PLOT, 'Z'
  360.     SURFACE, z2, x, y, ZRANGE=zrange, COLOR=2, /T3D, /NOERASE, $
  361.         XSTYLE=7, YSTYLE=7, ZSTYLE=7
  362.     SHADE_SURF, z2, x, y, ZRANGE=zrange, COLOR=2, /T3D, /NOERASE, $
  363.         XSTYLE=7, YSTYLE=7, ZSTYLE=7
  364.     img = TVRD(0, 0, drawXSize, drawYSize)
  365.     SET_PLOT, save_name
  366.     TV, img
  367.     EMPTY
  368.  
  369.     ig = [0.0, 0.0]
  370.  
  371.     PLOTS, [ig(0)], [ig(1)], [0.0], /DATA, COLOR=0, PSYM=1, /T3D, $
  372.         SYMSIZE=2.0, THICK=2
  373.     EMPTY
  374.  
  375.     sl = Nr_Newt(ig, 'TOUR_230_NEWT', /Double)
  376.     solString = $
  377.         'Solution:' + $
  378.         STRING(sl(0), FORMAT='(F7.4)') + ', ' + STRING(sl(1), FORMAT='(F7.4)')
  379.     sText.text[5] = solString
  380.     textChange = ['solve1','solve2', 'varia']
  381.     putTips, sText, wText[1], $
  382.        textChange, [0,1,2]
  383.  
  384.     PLOTS, [sl(0)], [sl(1)], [0.0], /DATA, COLOR=1, PSYM=1, /T3D, $
  385.         SYMSIZE=2.0, THICK=2
  386.     EMPTY
  387.  
  388.     SET_PLOT, 'Z'
  389.     DEVICE, /Close
  390.     SET_PLOT, save_name
  391.  
  392. end      ;   of MakeSolving
  393. ;
  394. ;--------------------------------------------------------------------
  395. ;
  396. ;  Purpose:  Generate a new data set for the integration demo and
  397. ;            display it. The window must be set apriori.
  398. ;
  399. pro GenerateIntegration, $
  400.     result           ;  OUT:  total area under the curve
  401.  
  402.  
  403.     ;  Initialize few parameters
  404.     ;
  405.     points = 21
  406.     points_m1 = points - 1
  407.     time = FINDGEN(points)
  408.     amplitude = RANDOMN(seed, points)
  409.     for i=1, points_m1 do begin
  410.         amplitude(i) = amplitude(i-1) + amplitude(i)
  411.     endfor
  412.     previousRegion = !P.REGION
  413.     !P.REGION = [0.1, 0.1, 0.9, 0.9]
  414.  
  415.     ;  Smooth the amplitude using a Low pass filter routine
  416.     ;
  417.     amplitude = SMOOTH(amplitude, 3, /EDGE_TRUNCATE)
  418.     min_amp = Min(amplitude, Max=max_amp)
  419.     min_amp = min_amp < 0.0
  420.     max_amp = max_amp > 0.0
  421.  
  422.     ;  Compute the integral
  423.     ;
  424.     result = INT_TABULATED(time, amplitude)
  425.  
  426.     ;  Display the result
  427.     ;
  428.     xx = CONGRID(time, 256, /INTERP, /MINUS_ONE)
  429.     yy = SPLINE(time, amplitude, xx)
  430.  
  431.     PLOT, time, amplitude, COLOR=15, TICKLEN=(0.02), $
  432.         XTITLE='Time', YTITLE='Amplitude', /NODATA, $
  433.         TITLE='Integration of Tabulated Data', $
  434.         YRANGE=[min_amp, max_amp]
  435.  
  436.     POLYFILL, [0.0, xx, FLOAT(points_m1)], [0.0, yy, 0.0], COLOR=14
  437.     EMPTY
  438.  
  439.     OPLOT, time, amplitude, COLOR=1, PSYM=10
  440.     OPLOT, time, amplitude, COLOR=2, PSYM=4, THICK=2
  441.     EMPTY
  442.  
  443.     OPLOT, xx, yy, COLOR=3, THICK=2
  444.     EMPTY
  445.  
  446.     PLOT, time, amplitude, COLOR=15, TICKLEN=(0.02), $
  447.         XTITLE='Time', YTITLE='Amplitude', /NODATA, $
  448.         TITLE='Integration of Tabulated Data', /NOERASE, $
  449.         YRANGE=[min_amp, max_amp]
  450.     EMPTY
  451.  
  452.     !P.REGION = previousRegion
  453.  
  454. end      ;   of GenerateIntegration
  455.  
  456.  
  457. ;--------------------------------------------------------------------
  458. ;
  459. pro D_Mathstat_Event,  $
  460.     sEvent       ; IN: event structure
  461.  
  462.     ;  Quit the application using the close box.
  463.     ;
  464.     if (TAG_NAMES(sEvent, /STRUCTURE_NAME) EQ $
  465.         'WIDGET_KILL_REQUEST') then begin
  466.         WIDGET_CONTROL, sEvent.top, /DESTROY
  467.         RETURN
  468.     endif
  469.  
  470.  
  471.     WIDGET_CONTROL, sEvent.id, GET_UVALUE=eventUValue
  472.  
  473.     case eventUValue of
  474.  
  475.         'DRAWING' : begin
  476.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sInfo, /NO_COPY
  477.             WIDGET_CONTROL, sInfo.wSelectButton, GET_VALUE=index
  478.             if (sEvent.type eq 1) then begin
  479.                 case index of
  480.  
  481.                     ;  Handle the solving equation demo.
  482.                     ;
  483.                     1 : begin
  484.                         nx = FLOAT(sEvent.x) / FLOAT(sInfo.drawXSize)
  485.                         ny = FLOAT(sEvent.y) / FLOAT(sInfo.drawYSize)
  486.                         ig = COORD2TO3(nx, ny, 2, 0.0)
  487.  
  488.                         PLOTS, [ig(0)], [ig(1)], [0.0], $
  489.                             /DATA, COLOR=0, PSYM=1, /T3D, $
  490.                             SYMSIZE=2.0, THICK=2
  491.  
  492.                         EMPTY
  493.                         sl = Nr_Newt(ig(0:1), 'TOUR_230_NEWT', /Double)
  494.                         solString = $
  495.                             'Solution:' + $
  496.                             (STRING(sl(0), FORMAT='(F7.4)') + $
  497.                             ', ' + STRING(sl(1), FORMAT='(F7.4)'))
  498.                         sInfo.sText.text[5] = solString
  499.                         textChange = ['solve1','solve2', 'varia']
  500.                         putTips, sInfo.sText, sInfo.wText[1], $
  501.                             textChange, [0,1,2]
  502.  
  503.                         PLOTS, [sl(0)], [sl(1)], [0.0], $
  504.                             /DATA, COLOR=1, PSYM=1, /T3D, $
  505.                             SYMSIZE=2.0, THICK=2
  506.                         EMPTY
  507.                     end     ;   of 1
  508.  
  509.                     ;  Handle the minimization button release.
  510.                     ;
  511.                     2 : begin
  512.  
  513.                         xpos = ((FLOAT(sEvent.x) / $
  514.                             FLOAT(sInfo.drawXSize)) - !X.S(0)) / !X.S(1)
  515.                         ypos = ((FLOAT(sEvent.y) /  $
  516.                             FLOAT(sInfo.drawYSize)) - !Y.S(0)) / !Y.S(1)
  517.  
  518.  
  519.                         OPLOT, [xpos], [ypos], PSYM=2, $
  520.                             COLOR=7, SYMSIZE=0.5
  521.                         EMPTY
  522.  
  523.                         p = [xpos, xpos]
  524.                         xi = REPLICATE(0.01, 2, 2)
  525.                         ftol = 1.0e-5
  526.  
  527.                         NR_Powell, p, xi, ftol, func_min, 'TOUR_231_FUNC'
  528.                         DEVICE, COPY=[0, 0, sInfo.drawXSize, $
  529.                             sInfo.drawYSize, 0, 0,  $
  530.                             sInfo.pixmapArray(0)]
  531.                         OPLOT, [xpos], [ypos], PSYM=2, $
  532.                              COLOR=7, SYMSIZE=0.5
  533.                         OPLOT, [p(0)], [func_min], PSYM=2, $
  534.                              COLOR=2, SYMSIZE=0.5
  535.                         OPLOT, [p(0)], [func_min], PSYM=4, $
  536.                             THICK=2, COLOR=2, SYMSIZE=2.0
  537.                         EMPTY
  538.                         minString = $
  539.                             'Minimum : ' + $
  540.                             (STRING(p(0), FORMAT='(F7.4)') + ', ' + $
  541.                             STRING(func_min, FORMAT='(F7.4)'))
  542.                         sInfo.sText.text[5] = minString
  543.                         textChange = ['optim1','optim2', 'varia']
  544.                         putTips, sInfo.sText, sInfo.wText[1], $
  545.                             textChange, [0,1,2]
  546.                     end    ;   of  2
  547.  
  548.                 endcase
  549.             endif
  550.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sInfo, /NO_COPY
  551.         end     ;  of  DRAWING
  552.  
  553.         'SELECT' : begin
  554.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sInfo, /NO_COPY
  555.             WSET, sInfo.drawWindowID
  556.             case sEvent.value of
  557.  
  558.                 ;  Bring up the integration plot.
  559.                 ;
  560.                 0 : begin
  561.                     WIDGET_CONTROL, sInfo.currentBase, MAP=0
  562.                     WIDGET_CONTROL, sInfo.wTopBase, SENSITIVE=0
  563.                     WIDGET_CONTROL, sInfo.wSelectionBase(0), MAP=1
  564.                     sInfo.currentBase = sInfo.wSelectionBase(0)
  565.                     WIDGET_CONTROL, sInfo.wAreaDraw, DRAW_BUTTON_EVENTS=0
  566.                     WSET, sInfo.drawWindowID
  567.                     ERASE
  568.                     GenerateIntegration, result
  569.                     statusString = $
  570.                         'Total Area : ' + STRING(result, FORMAT='(F9.4)')
  571.                     sInfo.sText.text[5] = statusString
  572.                     textChange = ['integ', 'curve','varia']
  573.                     putTips, sInfo.sText, sInfo.wText[1], $
  574.                         textChange, [0,1,2]
  575.                     WIDGET_CONTROL, sInfo.wTopBase, SENSITIVE=1
  576.                 end  ;  of 0
  577.  
  578.                 ;  Bring up the solving solution plot.
  579.                 ;
  580.                 1 : begin
  581.                     WIDGET_CONTROL, sInfo.wTopBase, SENSITIVE=0
  582.                     WIDGET_CONTROL, sInfo.currentBase, MAP=0
  583.                     WIDGET_CONTROL, sInfo.wSelectionBase(1), MAP=1
  584.                     sInfo.currentBase = sInfo.wSelectionBase(1)
  585.                     WSET, sInfo.drawWindowID
  586.                     ERASE
  587.                     MakeSolving, sInfo.drawXSize, $
  588.                         sInfo.drawYSize, sInfo.sText, sInfo.wText, $
  589.                         sInfo.drawWindowID
  590.                     WIDGET_CONTROL, sInfo.wAreaDraw, DRAW_BUTTON_EVENTS=1
  591.                     WIDGET_CONTROL, sInfo.wTopBase, SENSITIVE=1
  592.                 end   ; of 1
  593.  
  594.                 ;  Bring up the optimization (minimization) plot.
  595.                 ;
  596.                 2 : begin
  597.                     WIDGET_CONTROL, sInfo.wTopBase, SENSITIVE=0
  598.                     WIDGET_CONTROL, sInfo.currentBase, MAP=0
  599.                     WIDGET_CONTROL, sInfo.wSelectionBase(2), MAP=1
  600.                     sInfo.currentBase = sInfo.wSelectionBase(2)
  601.                     MakeMinimization, sInfo.drawXSize, $
  602.                         sInfo.drawYSize, sInfo.drawWindowID, $
  603.                         sInfo.pixmapArray(0), sInfo.sText, sInfo.wText
  604.                     WIDGET_CONTROL, sInfo.wAreaDraw, DRAW_BUTTON_EVENTS=1
  605.                     WIDGET_CONTROL, sInfo.wTopBase, SENSITIVE=1
  606.                 end   ;  of 2
  607.  
  608.                 ;  Bring up the linear regression plots.
  609.                 ;
  610.                 3 : begin
  611.                     above = 3
  612.                     below = 15
  613.                     WIDGET_CONTROL, sInfo.wTopBase, SENSITIVE=0
  614.                     WIDGET_CONTROL, sInfo.currentBase, MAP=0
  615.                     WIDGET_CONTROL, sInfo.wSelectionBase(3), MAP=1
  616.                     WIDGET_CONTROL, sInfo.wAboveSlider, SET_VALUE=above
  617.                     WIDGET_CONTROL, sInfo.wBelowSlider, SET_VALUE=below
  618.                     sInfo.currentBase = sInfo.wSelectionBase(3)
  619.                     WSET, sInfo.drawWindowID
  620.                     ERASE
  621.                     MakeRegression, above, below, $
  622.                         sInfo.drawWindowID
  623.                     textChange = ['regre1','regre2', 'regre3']
  624.                     putTips, sInfo.sText, sInfo.wText[1], $
  625.                             textChange, [0,1,2]
  626.                     WIDGET_CONTROL, sInfo.wAreaDraw, DRAW_BUTTON_EVENTS=0
  627.                     WIDGET_CONTROL, sInfo.wTopBase, SENSITIVE=1
  628.                 end    ;  of 3
  629.  
  630.                 ;  Bring up the polynomial best fit routine.
  631.                 ;
  632.                 4 : begin
  633.                     WIDGET_CONTROL, sInfo.wTopBase, SENSITIVE=0
  634.                     WIDGET_CONTROL, sInfo.currentBase, MAP=0
  635.                     WIDGET_CONTROL, sInfo.wSelectionBase(4), MAP=1
  636.                     sInfo.currentBase = sInfo.wSelectionBase(4)
  637.                     WIDGET_CONTROL, sInfo.wNPolySlider, SET_VALUE=32
  638.                     WIDGET_CONTROL, sInfo.wDegreeSlider, SET_VALUE=3
  639.                     nPoints = 32
  640.                     degree = 3
  641.                     WSET, sInfo.drawWindowID
  642.                     ERASE
  643.                     x = 2.0 * !PI * FINDGEN(nPoints) / FLOAT(nPoints - 1)
  644.                     y = SIN(x) + (0.5 * RANDOMN(seed, nPoints))
  645.                     sInfo.xPoly(0:nPoints-1) = x(0:nPoints-1)
  646.                     sInfo.yPoly(0:nPoints-1) = y(0:nPoints-1)
  647.                     MakePolyFit, nPoints, degree, $
  648.                         x, y, $
  649.                         sInfo.drawWindowID
  650.                     textChange = ['polyn1','polyn2', 'polyn3']
  651.                     putTips, sInfo.sText, sInfo.wText[1], $
  652.                             textChange, [0,1,2]
  653.                     WIDGET_CONTROL, sInfo.wAreaDraw, DRAW_BUTTON_EVENTS=0
  654.                     WIDGET_CONTROL, sInfo.wTopBase, SENSITIVE=1
  655.                 end    ;  of 4
  656.  
  657.                 ;  Show the surfce best fit plot.
  658.                 ;
  659.                 5 : begin
  660.                     WIDGET_CONTROL, sInfo.wTopBase, SENSITIVE=0
  661.                     WIDGET_CONTROL, sInfo.currentBase, MAP=0
  662.                     WIDGET_CONTROL, sInfo.wSelectionBase(5), MAP=1
  663.                     sInfo.currentBase = sInfo.wSelectionBase(5)
  664.                     WIDGET_CONTROL, sInfo.wNSurfaceSlider, SET_VALUE=13
  665.                     nPoints = 13
  666.                     WSET, sInfo.drawWindowID
  667.                     ERASE
  668.                     MakeSurfaceFit, nPoints, $
  669.                         sInfo.drawXSize, sInfo.drawYSIZE, $
  670.                         sInfo.drawWindowID
  671.                     textChange = ['surfa1','surfa2', 'surfa3']
  672.                     putTips, sInfo.sText, sInfo.wText[1], $
  673.                             textChange, [0,1,2]
  674.                     WIDGET_CONTROL, sInfo.wAreaDraw, DRAW_BUTTON_EVENTS=0
  675.                     WIDGET_CONTROL, sInfo.wTopBase, SENSITIVE=1
  676.                 end    ;  of 5
  677.  
  678.             endcase
  679.  
  680.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sInfo, /NO_COPY
  681.         end   ;                      of   SELECT
  682.  
  683.         ;  Generate a new integration plot.
  684.         ;
  685.         'GENERATE' : begin
  686.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sInfo, /NO_COPY
  687.             WIDGET_CONTROL, sInfo.wTopBase, SENSITIVE=0
  688.             WIDGET_CONTROL, sInfo.wAreaDraw, DRAW_MOTION=0
  689.             WSET, sInfo.drawWindowID
  690.             ERASE
  691.             GenerateIntegration, result
  692.             statusString = 'Total Area : ' + STRING(result, FORMAT='(F9.4)')
  693.             sInfo.sText.text[5] = statusString
  694.             textChange = ['varia']
  695.             putTips, sInfo.sText, sInfo.wText[1], $
  696.                 textChange, [2]
  697.             WIDGET_CONTROL, sInfo.wTopBase, SENSITIVE=1
  698.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sInfo, /NO_COPY
  699.         end    ;       of  GENERATE
  700.  
  701.         ;  Create a new data set with a specified number
  702.         ;  of outliers above the main cluster.
  703.         ;
  704.         'ABOVE' : begin
  705.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sInfo, /NO_COPY
  706.             WIDGET_CONTROL, sInfo.wAboveSlider, GET_VALUE=above
  707.             WIDGET_CONTROL, sInfo.wBelowSlider, GET_VALUE=below
  708.             WSET, sInfo.drawWindowID
  709.             ERASE
  710.             MakeRegression, above, below, $
  711.                 sInfo.drawWindowID
  712.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sInfo, /NO_COPY
  713.         end    ;       of  ABOVE
  714.  
  715.         ;  Create a new data set with a specified number
  716.         ;  of outliers below the main cluster.
  717.         ;
  718.         'BELOW' : begin
  719.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sInfo, /NO_COPY
  720.             WIDGET_CONTROL, sInfo.wAboveSlider, GET_VALUE=above
  721.             WIDGET_CONTROL, sInfo.wBelowSlider, GET_VALUE=below
  722.             WSET, sInfo.drawWindowID
  723.             ERASE
  724.             MakeRegression, above, below, $
  725.                 sInfo.drawWindowID
  726.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sInfo, /NO_COPY
  727.         end    ;       of  BELOW
  728.  
  729.         ;  Generate a new data set that has a specifed number
  730.         ;  of data points. Then display the best fit polynomial.
  731.         ;
  732.         'NPOLY' : begin
  733.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sInfo, /NO_COPY
  734.             WIDGET_CONTROL, sInfo.wNPolySlider, GET_VALUE=nPoints
  735.             WIDGET_CONTROL, sInfo.wDegreeSlider, GET_VALUE=degree
  736.             WSET, sInfo.drawWindowID
  737.             ERASE
  738.             x = 2.0 * !PI * FINDGEN(nPoints) / $
  739.                  FLOAT(nPoints - 1)
  740.             y = SIN(sInfo.xPoly) + (0.5 * RANDOMN(seed, nPoints))
  741.             sInfo.xPoly(0:nPoints-1) = x(0:nPoints-1)
  742.             sInfo.YPoly(0:nPoints-1) = y(0:nPoints-1)
  743.  
  744.             if (nPoints LE degree) then begin
  745.                 nPoints = degree + 1
  746.                 WIDGET_CONTROL, sInfo.wNPolySlider, Set_Value=nPoints
  747.                 x = 2.0 * !PI * FINDGEN(nPoints) / $
  748.                      FLOAT(nPoints - 1)
  749.                 y = SIN(sInfo.xPoly) + (0.5 * RANDOMN(seed, nPoints))
  750.                 sInfo.xPoly(0:nPoints-1) = x(0:nPoints-1)
  751.                 sInfo.YPoly(0:nPoints-1) = y(0:nPoints-1)
  752.             endif
  753.  
  754.             MakePolyFit, nPoints, degree, $
  755.                 x, y, $
  756.                 sInfo.drawWindowID
  757.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sInfo, /NO_COPY
  758.         end    ;       of  NPOLY
  759.  
  760.         ;  Recompute the best fit polynomial given the
  761.         ;  degree of that polynomial.
  762.         ;
  763.         'DEGREE' : begin
  764.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sInfo, /NO_COPY
  765.             WIDGET_CONTROL, sInfo.wNPolySlider, GET_VALUE=nPoints
  766.             WIDGET_CONTROL, sInfo.wDegreeSlider, GET_VALUE=degree
  767.             WSET, sInfo.drawWindowID
  768.             ERASE
  769.  
  770.             x = sInfo.xPoly(0:nPoints-1)
  771.             y = sInfo.yPoly(0:nPoints-1)
  772.             if (nPoints LE degree) then begin
  773.                 nPoints = degree + 1
  774.                 WIDGET_CONTROL, sInfo.wNPolySlider, Set_Value=nPoints
  775.                 x = 2.0 * !PI * FINDGEN(nPoints) / $
  776.                      FLOAT(nPoints - 1)
  777.                 y = SIN(sInfo.xPoly) + (0.5 * RANDOMN(seed, nPoints))
  778.                 sInfo.xPoly(0:nPoints-1) = x(0:nPoints-1)
  779.                 sInfo.YPoly(0:nPoints-1) = y(0:nPoints-1)
  780.             endif
  781.  
  782.             MakePolyFit, nPoints, degree, $
  783.                 x, y, $
  784.                 sInfo.drawWindowID
  785.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sInfo, /NO_COPY
  786.         end    ;       of  DEGREE
  787.  
  788.         ;  Compute and show the best fit surface given
  789.         ;  a specifed number of data points.
  790.         ;
  791.         'NSurface' : begin
  792.             WIDGET_CONTROL, sEvent.top, GET_UVALUE=sInfo, /NO_COPY
  793.             WIDGET_CONTROL, sInfo.wNSurfaceSlider, GET_VALUE=nPoints
  794.             WSET, sInfo.drawWindowID
  795.             ERASE
  796.             MakeSurfaceFit, nPoints, $
  797.                 sInfo.drawXSize, sInfo.drawYSIZE, $
  798.                 sInfo.drawWindowID
  799.             WIDGET_CONTROL, sInfo.wAreaDraw, DRAW_BUTTON_EVENTS=0
  800.             WIDGET_CONTROL, sEvent.top, SET_UVALUE=sInfo, /NO_COPY
  801.         end    ;       of  NSurface
  802.  
  803.         ;  Quit this application.
  804.         ;
  805.         'QUIT' : begin
  806.             WIDGET_CONTROL, sEvent.top, /DESTROY
  807.         end
  808.  
  809.         ;  Display the information text file.
  810.         ;
  811.         'ABOUT' : begin
  812.             if( Xregistered('XDisplayFile') ne 0) then RETURN
  813.             XDisplayFile, filepath("mathstat.txt", $
  814.                 SUBDIR=['examples','demo','demotext']), $
  815.                 DONE_BUTTON='Done', $
  816.                 TITLE="About mathematics and statistics", $
  817.                 GROUP=sEvent.top, WIDTH=55, HEIGHT=14
  818.         end           ;  of ABOUT
  819.  
  820.  
  821.         ELSE :   ;  do nothing
  822.  
  823.     endcase
  824. end
  825.  
  826. ;--------------------------------------------------------------------
  827. ;
  828. ;    PURPOSE  Cleanup procedure, restore the color table, destroy
  829. ;             the pixmaps.
  830. ;
  831. pro D_MathstatCleanup, $
  832.     wTopBase       ; IN: top level base identifier.
  833.  
  834.     ;  Get the color table saved in the window's user value
  835.     ;
  836.     WIDGET_CONTROL, wTopBase, GET_UVALUE=sInfo,/No_Copy
  837.  
  838.     ;  Restore the previous color table.
  839.     ;
  840.     TVLCT, sInfo.colorTable
  841.  
  842.     ;  Restore the previous plot font.
  843.     ;
  844.     !P.FONT = sInfo.plotFont
  845.  
  846.     ;  Delete the pixmaps
  847.     ;
  848.     for i = 0, sInfo.nPixmap-1 do begin
  849.         WDELETE, sInfo.pixmapArray(i)
  850.     endfor
  851.  
  852.     ;  Map the group leader base if it exists.
  853.     ;
  854.     if (WIDGET_INFO(sInfo.groupBase, /VALID_ID)) then $
  855.         WIDGET_CONTROL, sInfo.groupBase, /MAP
  856.  
  857. end   ; of D_MathstatCleanup
  858.  
  859. ;--------------------------------------------------------------------
  860. ;
  861. ;   PURPOSE Show several numerical routines available in IDL 5.0.
  862. ;           These are : integration of function,  solving equations,
  863. ;                       minimization (or optimization),  linear
  864. ;                       regression, best fit polynomial, and
  865. ;                       surface fit.
  866. ;
  867. pro D_Mathstat, $
  868.     GROUP=group, $     ; IN: (opt) group identifier
  869.     APPTLB = appTLB    ; OUT: (opt) TLB of this application
  870.  
  871.     ; Check the validity of the group identifier
  872.     ;
  873.     ngroup = N_ELEMENTS(group)
  874.     if (ngroup NE 0) then begin
  875.         check = WIDGET_INFO(group, /VALID_ID)
  876.         if (check NE 1) then begin
  877.             print,'Error, the group identifier is not valid'
  878.             print, 'Return to the main application'
  879.             RETURN
  880.         endif
  881.         groupBase = group
  882.     endif else groupBase = 0L
  883.  
  884.  
  885.     ;  Get the current color table. It will be restored when exiting.
  886.     ;
  887.     TVLCT, savedR, savedG, savedB, /GET
  888.     colorTable = [[savedR],[savedG],[savedB]]
  889.  
  890.     ;  Also save the font
  891.     ;
  892.     plotFont = !P.FONT
  893.  
  894.     ; Get the character scaling factor
  895.     ;
  896.     charscale = 8.0/!d.X_CH_SIZE
  897.  
  898.     ;  Load a new color table
  899.     ;
  900.     LOADCT, 12, /SILENT
  901.     TEK_COLOR
  902.  
  903.     ;  Use hardware-drawn font.
  904.     ;
  905.     !P.FONT=0
  906.  
  907.     ;  Get the tips.
  908.     ;
  909.     sText = getTips(filepath('mathstat.tip', $
  910.         SUBDIR=['examples','demo', 'demotext']) )
  911.  
  912.     ;  Determine hardware display size.
  913.     ;  Set the viewing area size.
  914.     ;
  915.     DEVICE, GET_SCREEN_SIZE = screenSize
  916.     drawXSize = 0.6 * screenSize(0)
  917.     drawYSize = 0.8 * drawXSize
  918.  
  919.     ;  Create the starting up message.
  920.     ;
  921.     if (ngroup EQ 0) then begin
  922.         drawbase = startmes()
  923.     endif else begin
  924.         drawbase = startmes(GROUP=group)
  925.     endelse
  926.  
  927.  
  928.     filterLength = 32
  929.  
  930.     ;  Create the widgets
  931.     ;
  932.     if (N_ELEMENTS(group) EQ 0) then begin
  933.         wTopBase = WIDGET_BASE(TITLE="Mathematics and Statistics", $
  934.             /COLUMN, $
  935.             MAP=0, $
  936.             /TLB_KILL_REQUEST_EVENTS, $
  937.             TLB_FRAME_ATTR = 1, MBAR=barBase)
  938.     endif else begin
  939.         wTopBase = WIDGET_BASE(TITLE="Mathematics and Statistics", $
  940.             GROUP_LEADER=group, $
  941.             /TLB_KILL_REQUEST_EVENTS, $
  942.             MAP=0, $
  943.             /COLUMN, $
  944.             TLB_FRAME_ATTR = 1, MBAR=barBase)
  945.     endelse
  946.  
  947.         ;  Create the menu bar items
  948.         ;
  949.         wFileButton = WIDGET_BUTTON(barBase, VALUE='File')
  950.  
  951.             wQuitButton = WIDGET_BUTTON(wFileButton, VALUE='Quit', $
  952.                 UVALUE='QUIT')
  953.  
  954.         wHelpButton = WIDGET_BUTTON(barBase, VALUE='About', /HELP)
  955.  
  956.             wAboutButton = WIDGET_BUTTON(wHelpButton, $
  957.                 VALUE='About Mathematics and Statistics', $
  958.                 UVALUE='ABOUT')
  959.  
  960.         ;  Create the left and right bases
  961.         ;
  962.         wTopRowBase = WIDGET_BASE(wTopBase, COLUMN=2)
  963.  
  964.             wLeftBase = WIDGET_BASE(wTopRowBase, /COLUMN)
  965.  
  966.                 wSelectButton = CW_BGROUP(wLeftBase, $
  967.                     ['Integration',    'Solving Equations', $
  968.                     'Minimization',    'Linear Regression', $
  969.                     'Polynomial Fit', 'Surface Fit'], $
  970.                     UVALUE='SELECT', /NO_RELEASE, /EXCLUSIVE)
  971.  
  972.                 ;  Create a base for each options
  973.                 ;
  974.                 wSelectionBase = LONARR(6)   ; 6 is the number of selections
  975.                 wTempBase = WIDGET_BASE(wLeftbase)
  976.  
  977.                     ;  Put the selection bases into the temporary (temp)
  978.                     ;  base. This way, the selection bases overlaps each
  979.                     ;  another. When the user select from wSelectButton,
  980.                     ;  only one selection base is mapped.
  981.                     ;
  982.                     for i=0, N_ELEMENTS(wSelectionbase)-1 do  begin
  983.                         wSelectionbase(i) = WIDGET_BASE(wTempBase, $
  984.                         UVALUE=0L, /COLUMN, MAP=0, YPAD=20)
  985.                     endfor
  986.  
  987.                         ;  Create the content of each selection base
  988.                         ;  Beginning with integration
  989.                         ;
  990.                         wIntegrationBase = WIDGET_BASE(wSelectionBase(0), $
  991.                             /COLUMN, /FRAME, /BASE_ALIGN_CENTER)
  992.  
  993.                             wGenerateButton = WIDGET_BUTTON(wIntegrationBase, $
  994.                                 VALUE='Generate New Data', UVALUE='GENERATE')
  995.  
  996.                         ;  Solving equations base, It has nothing...
  997.                         ;
  998.                         wSolvingBase = WIDGET_BASE(wSelectionBase(1), $
  999.                             /COLUMN)
  1000.  
  1001.                         ;  Minimization base, It has nothing...
  1002.                         ;
  1003.                         wMinimizationBase = WIDGET_BASE(wSelectionBase(2), $
  1004.                             /COLUMN)
  1005.  
  1006.                         ;  Regression base.
  1007.                         ;
  1008.                         wRegressionBase = WIDGET_BASE(wSelectionBase(3), $
  1009.                             /COLUMN, /FRAME)
  1010.  
  1011.                             wAboveSlider = WIDGET_SLIDER(wRegressionBase, $
  1012.                                 MINIMUM=1, MAXIMUM=25, $
  1013.                                 VALUE=3, $
  1014.                                 TITLE='Number of Points Above', UVALUE='ABOVE')
  1015.  
  1016.                             wBelowSlider = WIDGET_SLIDER(wRegressionBase, $
  1017.                                 MINIMUM=1, MAXIMUM=25, $
  1018.                                 VALUE=15, $
  1019.                                 TITLE='Number of Points Below', UVALUE='BELOW')
  1020.  
  1021.                         ;  Polynomial fit base.
  1022.                         ;
  1023.                         wPolynomialBase = WIDGET_BASE(wSelectionBase(4), $
  1024.                             /COLUMN, /FRAME)
  1025.  
  1026.                             wNPolySlider = WIDGET_SLIDER(wPolynomialBase, $
  1027.                                 MINIMUM=3, MAXIMUM=200, $
  1028.                                 VALUE=32, $
  1029.                                 TITLE='Number of Points', UVALUE='NPOLY')
  1030.  
  1031.                             wDegreeSlider = WIDGET_SLIDER(wPolynomialBase, $
  1032.                                 MINIMUM=1, MAXIMUM=8, $
  1033.                                 VALUE=3, $
  1034.                                 TITLE='Degree', UVALUE='DEGREE')
  1035.  
  1036.                         ;  Surface fit base.
  1037.                         ;
  1038.                         wSurfaceBase = WIDGET_BASE(wSelectionBase(5), $
  1039.                             /COLUMN, /FRAME)
  1040.  
  1041.                             wNSurfaceSlider = WIDGET_SLIDER(wSurfaceBase, $
  1042.                                 MINIMUM=3, MAXIMUM=50, VALUE=13, $
  1043.                                 TITLE='Number of Points', UVALUE='NSurface')
  1044.  
  1045.             wRightBase = WIDGET_BASE(wTopRowBase, /COLUMN)
  1046.  
  1047.                 wAreaDraw = WIDGET_DRAW(wRightBase, XSIZE=drawXSize, $
  1048.                     YSIZE=drawYSize, RETAIN=2, UVALUE='DRAWING')
  1049.  
  1050.         ;  Create tips texts.
  1051.         ;
  1052.         wStatusBase = WIDGET_BASE(wTopBase, MAP=0, /ROW)
  1053.  
  1054.             nWidgets = 2
  1055.             wText = LONARR(nWidgets)
  1056.             widTips, wStatusBase, sText.text, XSIZE=36, $
  1057.                 YSIZE=3, NWIDGETS=nWidgets, wText
  1058.  
  1059.     ;  Realize the widget hierarchy.
  1060.     ;
  1061.     WIDGET_CONTROL, wTopBase, /REALIZE
  1062.  
  1063.     ;  Size the tips widgets.
  1064.     ;
  1065.     sizeTips, wTopBase, wText, wStatusBase
  1066.  
  1067.     ;  Returns the top level base in the appTLB keyword.
  1068.     ;
  1069.     appTLB = wTopBase
  1070.  
  1071.     WIDGET_CONTROL, wSelectButton, SET_VALUE=0
  1072.  
  1073.     ; Determine the window value of plot window, wDraw1.
  1074.     ;
  1075.     WIDGET_CONTROL, wAreaDraw, GET_VALUE=drawWindowID
  1076.  
  1077.     ;  Map the integration demo (index 0) as default
  1078.     ;
  1079.     WIDGET_CONTROL, wSelectionBase(0), MAP=1
  1080.  
  1081.     ;  Generate the integration data set and display it.
  1082.     ;
  1083.     WSET, drawWindowID
  1084.     ERASE
  1085.     GenerateIntegration, result
  1086.     statusString = 'Total Area : ' + STRING(result, FORMAT='(F9.4)')
  1087.     sText.text[5] = statusString
  1088.     textChange = ['integ', 'curve', 'varia']
  1089.     putTips, sText, wText[1], $
  1090.         textChange, [0,1,2]
  1091.  
  1092.     ;  Create the pixmaps
  1093.     ;
  1094.     nPixmap = 1
  1095.     pixmapArray = LONARR(nPixmap)
  1096.     for i = 0, nPixmap-1 do begin
  1097.         Window, /FREE, XSIZE=drawXSize, YSIZE=drawYSize, /PIXMAP
  1098.         pixmapArray(i) = !D.Window
  1099.     endfor
  1100.  
  1101.  
  1102.     ;  Create the info structure
  1103.     ;
  1104.     sInfo = { $
  1105.         XPoly: FLTARR(200), $                ; Polynomial x ans y data set
  1106.         YPoly: FLTARR(200), $
  1107.         NPixmap: nPixmap, $                  ; Number of pixmaps
  1108.         PixmapArray: pixmapArray, $          ; Pixmap ID array
  1109.         DrawXSize: drawXSize, $              ; Size of drawing area
  1110.         DrawYSize: drawYSize, $
  1111.         CurrentBase : wSelectionBase(0), $   ; ID of current base
  1112.         ColorTable:colorTable, $             ; Color table to restore
  1113.         CharScale: charScale, $              ; Character scale factor
  1114.         DrawWindowID: drawWindowID, $        ; Window ID
  1115.         WTopBase: wTopBase, $                ; Top level base
  1116.         WSelectionBase: wSelectionBase, $    ; Selecton base ID
  1117.         WSelectButton: wSelectButton, $      ; Buttons and sliders IDs
  1118.         WGenerateButton: wGenerateButton, $  ; Generate new data button
  1119.         WAboveSlider: wAboveSlider, $        ; Set number of outlier above
  1120.         WBelowSlider: wBelowSlider, $        ; Set the number of outlier below
  1121.         WNPolySlider: wNPolySlider, $        ; Number of points for the polynomial
  1122.         WDegreeSlider: wDegreeSlider, $      ; Degree of the polynomial
  1123.         WNSurfaceSlider: wNSurfaceSlider, $  ; Number of points for surface fit
  1124.         WAreaDraw: wAreaDraw, $              ; Widget draw ID
  1125.         WText: wText, $                      ; Widget text IDs for tips
  1126.         SText: sText, $                      ; Text structure for tips.
  1127.         plotFont: plotFont, $                ; Font to restore
  1128.         groupBase: groupBase $               ; Base of Group Leader
  1129.     }
  1130.  
  1131.     ;  Register the info structure in the user value of the top-level base
  1132.     ;
  1133.     WIDGET_CONTROL, wTopBase, SET_UVALUE=sInfo, /NO_COPY
  1134.  
  1135.     ;  Destroy the starting up window.
  1136.     ;
  1137.     WIDGET_CONTROL, drawbase, /DESTROY
  1138.  
  1139.     ;  Map the top level base.
  1140.     ;
  1141.     WIDGET_CONTROL, wTopBase, MAP=1
  1142.  
  1143.     ; Register with the BIG GUY, XMANAGER!
  1144.     ;
  1145.     XMANAGER, "D_Mathstat", wTopBase, /NO_BLOCK, $
  1146.         EVENT_HANDLER = "D_Mathstat_Event", CLEANUP="D_MathstatCleanup"
  1147.  
  1148. end   ; of d_mathstat
  1149.